#include <bits/stdc++.h>

using namespace std;
struct _TreeNode {
    int idx;
    vector<_TreeNode *> sons;
    int pathSum, _treeNodesNum;
    _TreeNode(int idx) :idx(idx), pathSum(0), _treeNodesNum(1) {}
};
class Solution {
    vector<int> ans;
    int n;
    _TreeNode *buildTree(vector<unordered_set<int>> &edges, int nodeidx, unordered_set<int> &visited) {
        _TreeNode *root = new _TreeNode(nodeidx);
        visited.emplace(nodeidx);
        for (int v : edges[nodeidx]) {
            if (visited.count(v)) { continue; }
            _TreeNode *son = buildTree(edges, v, visited);
            root->sons.push_back(son);
            root->pathSum += son->pathSum + son->_treeNodesNum;
            root->_treeNodesNum += son->_treeNodesNum;
        }
        return root;
    }
    void dfs(_TreeNode *root) {
        ans[root->idx] = root->pathSum;
        for (_TreeNode *son : root->sons) {
            son->pathSum =
                +root->pathSum - son->_treeNodesNum
                + n - son->_treeNodesNum;
            dfs(son);
        }
    }
public:
    vector<int> sumToAllpoints(vector<unordered_set<int>> &edges) {
        n = edges.size();
        ans.clear();
        ans.resize(n, 0);
        unordered_set<int> visited;
        _TreeNode *root = buildTree(edges, rand() % n, visited);
        dfs(root);
        return ans;
    }
};

int main() {
    int N;
    cin >> N;
    vector<unordered_set<int>> edges(N);
    int x, y;
    while (--N > 0) {
        cin >> x >> y;
        edges[x].emplace(y);
        edges[y].emplace(x);
    }
    for (auto &n : Solution().sumToAllpoints(edges)) {
        cout << n << ' ';
    }
    //system("pause");
    return 0;
}
